package kr.saeildamil.androidforstudy2.ch31;

import java.util.ArrayList;

import kr.saeildamil.androidforstudy2.R;
import android.app.Activity;
import android.gesture.Gesture;
import android.gesture.GestureLibrary;
import android.gesture.GestureOverlayView;
import android.gesture.GestureOverlayView.OnGesturePerformedListener;
import android.gesture.Prediction;
import android.os.Bundle;
import android.widget.TextView;

public class CustomGesture extends Activity {
	TextView mTextCount;
	int mCount = 10;
	GestureLibrary mLibrary;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch31_customgesture);
		
		mTextCount = (TextView) findViewById(R.id.count);
		mTextCount.setText("" + mCount);
		
		// mLibrary = GestureLibraries.fromRawResource(this, R.raw.gestures);
		if(mLibrary.load() == false){
			finish();
		}
		
		GestureOverlayView gestures = (GestureOverlayView) findViewById(R.id.gestures);
		gestures.addOnGesturePerformedListener(mListener);
		
	}
	
	OnGesturePerformedListener mListener = new OnGesturePerformedListener() {
		
		@Override
		public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
			ArrayList<Prediction> predictions = mLibrary.recognize(gesture);
			
			if(predictions.size() != 0){
				Prediction prediction = predictions.get(0);
				String name = prediction.name;
				if(prediction.score > 1.0){
					if(name.equals("kiyuk")){
						mCount ++;
					}else if(name.equals("Niun")){
							mCount--;
					}else if(name.equals("Digut")){
						mCount = 10;
						}
					mTextCount.setText("" + mCount);
					}
				}
			}
	};
	
}
	

